package com.dangdang.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class MDUtils {
	public static String md5(String str){
		try {
			//获得一个基于md5的算法运算器
			MessageDigest md = MessageDigest.getInstance("md5");
			//把字符串变成字节数组
			byte[] bs = str.getBytes();		
			//digest是摘要运算。返回的是一个字节数组
			byte[]  bt  = md.digest(bs);		
			//把摘要运算得到的数组编码成字符串
			BASE64Encoder encoder = new BASE64Encoder();
			String tt = encoder.encode(bt);
			return tt;
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static void main(String[] args) {
		String password  = "王培虎";
		String pwd = md5(password);
		System.out.println(pwd);
	}
}
